<?php

$this->PhpExcel->Excel();
$this->PhpExcel->titulo_reporte("BOLETAS AGROPATRIA","LISTADO DE BOLETAS");
$this->PhpExcel->titulo_hoja("LISTADOBOLETAS");

$listadoReporte = array('normal' => 'Normal','detallado' => 'Detallado');
$ext = ($tipo == 1) ? 'xlsx' : 'ods';
$nombre = "LISTADO_BoletaES".date("d_m_Y");
	

$this->PhpExcel->hoja->getDefaultStyle()->applyFromArray(array('font' => array('name' => 'arial','size' => 10)));
$this->PhpExcel->hoja->getStyle('A1')->applyFromArray(array('font' => array('bold' => true, 'size' => 12, 'color' => array('rgb' => '8B0000'))));
$this->PhpExcel->hoja->getStyle('A2')->applyFromArray(array('font' => array('bold' => true, 'size' => 11)));
$this->PhpExcel->hoja->getStyle('A3')->applyFromArray(array('font' => array('bold' => false,'size' => 10)));
$this->PhpExcel->hoja->getStyle('A4')->applyFromArray(array('font' => array('bold' => false,'size' => 10)));

$arrStyleTitle = array( 'fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID,
										'startcolor' => array('rgb' => '81DAF5')),
						'font' => array('bold' => true, 
							 			'color' => array('rgb' => PHPExcel_Style_Color::COLOR_WHITE)),
				        'alignment' => array('horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER));

$arrStyleTitleuno = array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID,
				                          'startcolor' => array('rgb' => 'EFFBFB')));

$arrborderTitleuno = array('style' => PHPExcel_Style_Border::BORDER_DASHDOT,'color' => array('rgb' => '000000'));
			     
$this->PhpExcel->configura_celda('A',5); //#
$this->PhpExcel->configura_celda('B',25); //RUBRO
$this->PhpExcel->configura_celda('C',30); //PRODUCTOR
$this->PhpExcel->configura_celda('D',12); //CEDULA/RIF
$this->PhpExcel->configura_celda('E',12); //BOLETA
$this->PhpExcel->configura_celda('F',12); //Nro. ORDEN
$this->PhpExcel->configura_celda('G',12); //KILOS
$this->PhpExcel->configura_celda('H',12); //BsF / Kg RUBRO
$this->PhpExcel->configura_celda('I',12); //FECHA
$this->PhpExcel->configura_celda('J',20); //ESTATUS

$this->PhpExcel->hoja->setAutoFilter('A6:J6'); // AUTO FILTER
$index_title=6;
$index_detail=0;

$j=0;
$tit[] = array('#','STR','C');
$tit[] = array('RUBRO','STR','C');
$tit[] = array('PRODUCTOR','STR','C');
$tit[] = array('CEDULA/RIF','STR','C');
$tit[] = array('N. BOLETA','STR','C');
$tit[] = array('N. ORDEN','STR','C');
$tit[] = array('KILOS','STR','C');
$tit[] = array('Bs BOLETA','STR','C');
$tit[] = array('FECHA','STR','C');
$tit[] = array('ESTATUS','STR','C');

foreach($tit as $columnTitle)
{
	$this->PhpExcel->valor_celda($j, $index_title, $columnTitle);
	$oColumn = $this->PhpExcel->obtener_columna($j, $index_title);
	$oRow = $this->PhpExcel->obtener_fila($j, $index_title);
	$this->PhpExcel->hoja->getStyle($oColumn.$oRow)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
	$this->PhpExcel->hoja->getStyle($oColumn.$oRow)->applyFromArray($arrStyleTitle);
	$this->PhpExcel->hoja->getStyle($oColumn.$oRow)->getBorders()->getAllBorders()->applyFromArray( $arrborderTitleuno);
	$j++;
}

$fila = 7;
$ea=0;
for($i=0; $i<count($data); $i++)
{
	if($data[$i]['Boleta']['estatus']==1) $estatus="SIN FACTURAR";
	else if($data[$i]['Boleta']['estatus']==2) $estatus="ANULADA";
	else $estatus="FACTURADA";
  $rubro=$this->Interfaz->mayuscula($data[$i]['Rubro']['nombre']);
	$pro=$data[$i]['Productor']['nombre'];
	$cedrif=$data[$i]['Productor']['ced_rif'];
	$boleta=$data[$i]['Boleta']['nro_boleta'];
	$orden=$data[$i]['Boleta']['nro_orden'];
	$kilos=$data[$i]['Boleta']['kilos'];
	$monto=$data[$i]['Boleta']['monto'];
	$fecha=$this->Interfaz->fecha($data[$i]['Boleta']['fecha']);

	$valores = array();
	$valores[] = array(($i+1),'STR','C');
	$valores[] = array($rubro,'STR','L');
	$valores[] = array($pro,'STR','L');
	$valores[] = array($cedrif,'STR','L');
	$valores[] = array($boleta,'STR','L');
	$valores[] = array($orden,'STR','L');
  $valores[] = array($kilos,'N','R');
  $valores[] = array($monto,'N','R');
	$valores[] = array($fecha,'STR','L');
	$valores[] = array($estatus,'STR','C');
	$columna=0;
	foreach($valores as $valor)
	{
		$this->PhpExcel->valor_celda($columna, $fila,  $valor);
		$oColumn = $this->PhpExcel->obtener_columna($columna, $fila);
		$oRow = $this->PhpExcel->obtener_fila($columna, $fila);
		if($fila%2==0)
		{
			$this->PhpExcel->hoja->getStyle($oColumn.$oRow)->applyFromArray($arrStyleTitleuno);
		}
		$this->PhpExcel->hoja->getStyle($oColumn.$oRow)->getBorders()->getAllBorders()->applyFromArray($arrborderTitleuno);
		$columna++;
	}
    $fila++;
    $ea++;
	
}



$this->PhpExcel->mostrar($nombre,$ext);


?>